package cn.com.mall.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.com.mall.product.entity.CategoryEntity;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.com.mall.product.entity.CategoryBrandRelationEntity;
import cn.com.mall.product.service.CategoryBrandRelationService;
import cn.com.mall.common.utils.PageUtils;
import cn.com.mall.common.utils.R;



/**
 * 品牌分类关联
 *
 * @author yangwen
 * @email yangwen@servyou.com.cn
 * @date 2020-04-09 23:52:34
 */
@RestController
@RequestMapping("product/categorybrandrelation")
public class CategoryBrandRelationController {
    @Autowired
    private CategoryBrandRelationService categoryBrandRelationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = categoryBrandRelationService.queryPage(params);

        return R.ok().put("page", page);
    }



    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		CategoryBrandRelationEntity categoryBrandRelation = categoryBrandRelationService.getById(id);

        return R.ok().put("categoryBrandRelation", categoryBrandRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){

		categoryBrandRelationService.saveDetail(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CategoryBrandRelationEntity categoryBrandRelation){
		categoryBrandRelationService.updateById(categoryBrandRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		categoryBrandRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * 根据品牌id获取分类列表
     * @param brandId
     * @return
     */
    @RequestMapping("/catelog/list")
    public R getCatelogListByBrandId(@RequestParam("brandId") Long brandId){
        List<CategoryBrandRelationEntity> categoryBrandRelationEntities=categoryBrandRelationService.getCatelogListByBrandId(brandId);

        return R.ok().put("data",categoryBrandRelationEntities);

    }

    /**
     * 根据分类id获取品牌列表
     * @param catId
     * @return
     */
//    /product/categorybrandrelation/brands/list
    @RequestMapping("/brands/list")
    public R getBrandListByCatelogId(@RequestParam("catId") Long catId){
        List<CategoryBrandRelationEntity> catelogList=categoryBrandRelationService.getBrandListByCatelogId(catId);

        return R.ok().put("data",catelogList);

    }
}
